﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdvCMS.Data.Repositories;

namespace AdvCMS.Data.Linq.Repositories
{
    public class SettingRepository : ISettingRepository
    {
        public AdvCMS.Data.Linq.SettingDataContext DataContext { get; set; }
        public IAdvSetting Create()
        {
            return new AdvSetting();
        }

        public IList<IAdvSetting> FindAll()
        {
            return DataContext.AdvSettings.ToList<IAdvSetting>();
        }

        public IAdvSetting Get(int id)
        {
            return DataContext.AdvSettings.FirstOrDefault(x => x.Id == id);
        }

        public IAdvSetting GetByCode(string code)
        {
            return DataContext.AdvSettings.FirstOrDefault(x => x.Key == code);
        }

        public void Insert(IAdvSetting obj)
        {
            DataContext.AdvSettings.InsertOnSubmit((AdvSetting)obj);
        }

        public void Delete(IAdvSetting obj)
        {
            DataContext.AdvSettings.DeleteOnSubmit((AdvSetting)obj);
        }

        public void Update()
        {
            DataContext.SubmitChanges();
        }
    }
}
